
package tsg.graphic;

import tsg.shape.Polygon;
import tsg.shape.Rectangle;
import tsg.util.Point;

public class PCGraphics extends Graphics
{
	protected PCGraphics(Rectangle rectangle, Graphics parentGraphics, java.awt.Graphics graphicsContext)
	{
		super(rectangle, parentGraphics);
		_graphicsContext = graphicsContext;
	}

	
	public PCGraphics(Rectangle rectangle, java.awt.Graphics graphicsContext) 
	{
		this(rectangle, null, graphicsContext);
	}

	public Graphics createSubGraphics(Rectangle rectangle, Graphics parentGraphics) 
	{
		// TODO
		return null;
	}


	public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
	{
		_graphicsContext.drawArc(x, y, width, height, startAngle, arcAngle);
	}


	public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
	{
		_graphicsContext.fillArc(x, y, width, height, startAngle, arcAngle);
	}

	public void drawOval(int x, int y, int width, int height) 
	{
		_graphicsContext.drawOval(x, y, width, height);
	}


	public void fillOval(int x, int y, int width, int height) 
	{
		_graphicsContext.fillOval(x, y, width, height);
	}


	public void drawPolygon(Polygon polygon) 
	{
		Point[] points = polygon.getPoints();
		int[]   xArray = new int[points.length];
		int[]   yArray = new int[points.length];
		
		for(int i=0; i<points.length; i++)
		{
			xArray[i] = points[i].getX();
			yArray[i] = points[i].getY();
		}

		_graphicsContext.drawPolygon(xArray, yArray, points.length);
	}


	public void fillPolygon(Polygon polygon) 
	{
		Point[] points = polygon.getPoints();
		int[]   xArray = new int[points.length];
		int[]   yArray = new int[points.length];
		
		for(int i=0; i<points.length; i++)
		{
			xArray[i] = points[i].getX();
			yArray[i] = points[i].getY();
		}

		_graphicsContext.fillPolygon(xArray, yArray, points.length);
	}


	public void drawRectangle(int x, int y, int width, int height) 
	{
		_graphicsContext.drawRect(x, y, width, height);
	}


	public void fillRectangle(int x, int y, int width, int height) 
	{
		_graphicsContext.fillRect(x, y, width, height);
	}


	public void drawRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) 
	{
		_graphicsContext.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
	}


	public void fillRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) 
	{
		_graphicsContext.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
	}


	public void drawImage(Image image, int x, int y) 
	{
		// TODO
	}


	public void drawImage(Image image, int x, int y, Rectangle imageRectangle) 
	{
		// TODO
	}

	
	public void drawLine(int x1, int y1, int x2, int y2) 
	{
		_graphicsContext.drawLine(x1, y1, x2, y2);
	}

	
	public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) 
	{
		_graphicsContext.drawPolyline(xPoints, yPoints, nPoints);
	}

	
	public void drawString(String string, int x, int y) 
	{
		_graphicsContext.drawString(string, x, y);
	}

	
	public Color getColor() 
	{
		return super.getColor();
	}

	
	public void setColor(Color color) 
	{
		_graphicsContext.setColor(new java.awt.Color(color.getRed(), color.getGreen(), color.getBlue()));
		super.setColor(color);
	}

	
	public Font getFont() 
	{
		return _font;
	}


	public void setFont(Font font) 
	{
		_font = font;
		_graphicsContext.setFont(((tsg.graphic.PCFont)font.getSystemFont()).getAWTFont());
	}


	public void translate(int x, int y) 
	{
		_graphicsContext.translate(x, y);
	}

	
	private java.awt.Graphics 	_graphicsContext 	= null;
	private Font				_font				= null;
}
